home *** CD-ROM | disk | FTP | other *** search
- Path: in1.uu.net!zdc!zippo!drn
- From: Clarence Chiang
- Newsgroups: comp.lang.c++
- Subject: Re: Creating an object via new with ONLY a pointer to the object
- Date: 11 Apr 1996 12:21:42 -0700
- Organization: Spider Island Software
- Sender: http@doc.zippo.com
- Message-ID: <4kjm46$pht@doc.zippo.com>
- References: <4kh07v$lno@crchh327.rich.bnr.ca> <4kifrt$lk1@ubszh.fh.zh.ubs.com>
- NNTP-Posting-Host: doorstop.spiderisland.com
-
- In article <316CFD17.5656@ebc.ericsson.se>, Bjorn says...
- >
- >Ian Johnston (by ubsswop) wrote:
- >>
- >> In article <4kh07v$lno@crchh327.rich.bnr.ca>, jobell@bnr.ca (Bret Bieghler) writes:
- >> |> An interesting problem I've come across... I was wondering if this
- >> |> is possible:
- >> |>
- >> |> I have a generic CommandObject which defines several pure virtual
- >> |> functions. Derived from CommandObject are user commands, such
- >> |> as ExitCommand, StatusCommand, etc.
- >> |>
- >> |> To process a command (currently) I do the following:
- >> |>
- >> |> CommandObject* basePtr;
- >> |>
- >> |> if (command == "exit")
- >> |> {
- >> |> basePtr = new ExitCommand;
- >> |> basePtr->implement();
- >> |> }
- >> |> else if (command == "status")
- >> |> {
- >> |> basePtr = new StatusCommand;
- >> |> basePtr->implement();
- >> |> }
- >> |>
- >> |> What I would LIKE to do is the the following:
- >> |>
- >> |> CommandObject* basePtr = new commandTable[command];
- >> |>
- >> |> where commandTable is an associative array as follows:
- >> |>
- >> |> Key Value
- >> |> "exit" ExitCommand*
- >> |> "status" StatusCommand*
-
- Or you can use the Factory Method pattern. It, with many other very good design
- patterns, are discussed in the book "Design Patterns". I forget the names of the
- authors though.
-
- Basically you will have a CommandFactory class which its sole purpose is so
- create different command objects.
-
- Clarence Chiang
- Spider Island Software
-